package jnpf.util;


import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;

/**
 * 自定义异常
 *
 * @author ruoyi
 */
public class CustomException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private Integer code;

    private String message;

    public CustomException(String message) {
        this.message = message;
        this.code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }

    public CustomException(String message, Integer code) {
        this.message = message;
        this.code = code == null ? HttpStatus.SC_INTERNAL_SERVER_ERROR : code;
    }

    public CustomException(String message, Throwable e) {
        super(message, e);
        this.message = message;
        this.code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }


    public CustomException(String message, Integer code, Throwable e) {
        super(message, e);
        this.message = message;
        this.code = code == null ? HttpStatus.SC_INTERNAL_SERVER_ERROR : code;
    }

    @Override
    public String getMessage() {
        return StringUtils.isBlank(message) ? "发生异常" : message;
    }

    public Integer getCode() {
        return code;
    }
}
